<?php
if(!defined('DEDEINC'))
{
	exit("Request Error!");
}
//orderby = logintime(login new) or mid(register new)
function lib_memadlist(&$ctag,&$refObj)
{
	global $dsql,$sqlCt;
	$attlist="row|1,orderby|lists,titlen|18,father|0,id|0";
	FillAttsDefault($ctag->CAttribute->Items,$attlist);
	extract($ctag->CAttribute->Items, EXTR_SKIP);

	$revalue = '';
	$innerText = trim($ctag->GetInnerText());
	if(empty($innerText)) $innerText = GetSysTemplets('memberlist.htm');
	$wheresql = " where cid>0 ";
    if($father > 0)
	{
	  $wheresql .= " And tid='$father' ";
	}
    if($id > 0)
	{
	  $wheresql .= " And cid='$id' ";
	}    
	$sql = "Select * From `#@__memad` $wheresql order by {$orderby} desc limit 0,$row ";

	$ctp = new DedeTagParse();
	$ctp->SetNameSpace('field','[',']');
	$ctp->LoadSource($innerText);

	$dsql->Execute('memad',$sql);
	while($row = $dsql->GetArray('memad'))
	{
		$ntime = time();
        if(!eregi('^http:',$row['normurl']))
		{
			$row['normurl']="http://".$row['normurl'];
		}
		$row['adbody']=$row['normbody'];
		$row['adurl']=$row['normurl'];
	    if($ntime>$row['endtime'] || $ntime<$row['starttime'])
	     {
		  $row['adbody']=$row['expbody'];
		  $row['adurl']=$row['expurl'];
	     }

		foreach($ctp->CTags as $tagid=>$ctag){
			if(isset($row[$ctag->GetName()])){ $ctp->Assign($tagid,$row[$ctag->GetName()]); }
		}
		$revalue .= $ctp->GetResult();
	}
	return $revalue;
}
?>